//
//  MTUserNotifyModel.swift
//  MT
//
//  Created by ooops on 2020/6/9.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import ObjectMapper


/// 对应接口最外层数据类
class MTUserNotifyModel: Mappable {
    /// 请求是否成功的code
    public var code: Int?
    /// 请求返回的Message
    public var message: String?
    /// 分页对象
    public var page: PageModel?
    /// 时间戳
    public var timestamp: TimeInterval?
    
    public var result: [MTUserNotifySubModel]?
    
    public var giftInfo: [MTUserNotifySubModel]?
    
    private var giftInfoString: String? {
        didSet {
            if let jsonData:Data = giftInfoString?.data(using: .utf8) {
             
                if let array: [[String : Any]] = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers) as? [[String : Any]] {
                
                    var lists: [MTUserNotifySubModel]? = []
                    for(_, v) in array.enumerated() {
                        if let m = MTUserNotifySubModel(JSON: v) {
                            lists?.append(m)
                        }
                    }
                    giftInfo = lists
                }
            }
        }
    }
    
    required public init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        code    <- map["code"]
        message <- map["message"]
        page <- map["page"]
        timestamp <- map["timestamp"]
        result  <- map["result"]
        giftInfoString  <- map["giftInfo"]
    }
}


class GiftInfoform: TransformType {
    func transformFromJSON(_ value: Any?) -> String? {
        return nil
    }
    
    func transformToJSON(_ value: String?) -> String? {
        if let jsonData:Data = value?.data(using: .utf8) {
         
            if let array = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers) {
            
                return array as? String
            }
            return nil
        }
        return nil
    }
}

/// 对应接口最外层数据类
class MTUserNotifySubModel: Mappable {
    
    /// gift id
    var id: Int?
    /// 极光服务器消息ID
    var msgId: Int?
    /// 礼物状态 - 0 - 正常状态, 1 - 已领取, 2 - 已失效
    var status: Int?
    
    required public init?(map: Map) {
        
    }
    
    open func mapping(map: Map) {
        id    <- map["id"]
        msgId <- map["msgId"]
        status <- map["status"]
    }
}
